package model;

import java.sql.*;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import util.HtmlUtil;
import util.StringUtil;

import bll.ITreeNode;
import dal.*;

public class QuotationItemModel implements IModel, ITreeNode {

	public static class FieldNames {
		public static String Id = "Id";
		public static String IdQuotation = "IdQuotation";
		public static String IdParent = "IdParent";
		public static String Code = "Code";
		public static String Name = "Name";
		public static String Description = "Description";
		public static String Remark = "Remark";
		public static String IsGroup = "IsGroup";
		public static String Index = "Index";
		public static String DisplayIndex = "DisplayIndex";
		public static String IdProduct = "IdProduct";
		public static String IdService = "IdService";
		public static String IdUnit = "IdUnit";
		public static String IdCurrency = "IdCurrency";
		public static String EstimateQuantity = "EstimateQuantity";
		public static String QuotationQuantity = "QuotationQuantity";
		public static String InternalQuantity = "InternalQuantity";
		public static String EstimateUnitCost = "EstimateUnitCost";
		public static String QuotationUnitCost = "QuotationUnitCost";
		public static String InternalUnitCost = "InternalUnitCost";
		public static String EstimateTotalAmount = "EstimateTotalAmount";
		public static String QuotationTotalAmount = "QuotationTotalAmount";
		public static String InternalTotalAmount = "InternalTotalAmount";
		public static String InEstimate = "InEstimate";
		public static String InQuotation = "InQuotation";
		public static String InInternal = "InInternal";
		public static String IdType = "IdType";
		public static String Status = "Status";
		public static String Notification = "Notification";
		public static String Created = "Created";
		public static String Creator = "Creator";
		public static String Updated = "Updated";
		public static String Updator = "Updator";
		public static String Deleted = "Deleted";
		public static String DeletionTime = "DeletionTime";

	}

	public class ErrorMessages {
		public String Id = "";
		public String IdQuotation = "";
		public String IdParent = "";
		public String Code = "";
		public String Name = "";
		public String Description = "";
		public String Remark = "";
		public String IsGroup = "";
		public String Index = "";
		public String DisplayIndex = "";
		public String IdProduct = "";
		public String IdService = "";
		public String IdUnit = "";
		public String IdCurrency = "";
		public String EstimateQuantity = "";
		public String QuotationQuantity = "";
		public String InternalQuantity = "";
		public String EstimateUnitCost = "";
		public String QuotationUnitCost = "";
		public String InternalUnitCost = "";
		public String EstimateTotalAmount = "";
		public String QuotationTotalAmount = "";
		public String InternalTotalAmount = "";
		public String InEstimate = "";
		public String InQuotation = "";
		public String InInternal = "";
		public String IdType = "";
		public String Status = "";
		public String Notification = "";
		public String Created = "";
		public String Creator = "";
		public String Updated = "";
		public String Updator = "";
		public String Deleted = "";
		public String DeletionTime = "";

	}

	public ErrorMessages errMsgs = new ErrorMessages();

	public String[] errMsgList = null;

	// private variables
	private int _id = Integer.MIN_VALUE;
	private int _id_quotation = Integer.MIN_VALUE;
	private int _id_parent = Integer.MIN_VALUE;
	private String _code = null;
	private String _name = null;
	private String _description = null;
	private String _remark = null;
	private boolean _is_group = false;
	private boolean _isis_groupSet = false;
	private int _index = Integer.MIN_VALUE;
	private String _display_index = null;
	private int _id_product = Integer.MIN_VALUE;
	private int _id_service = Integer.MIN_VALUE;
	private int _id_unit = Integer.MIN_VALUE;
	private int _id_currency = Integer.MIN_VALUE;
	private int _estimate_quantity = Integer.MIN_VALUE;
	private int _quotation_quantity = Integer.MIN_VALUE;
	private int _internal_quantity = Integer.MIN_VALUE;
	private double _estimate_unit_cost = Double.MAX_VALUE;
	private double _quotation_unit_cost = Double.MAX_VALUE;
	private double _internal_unit_cost = Double.MAX_VALUE;
	private double _estimate_total_amount = Double.MAX_VALUE;
	private double _quotation_total_amount = Double.MAX_VALUE;
	private double _internal_total_amount = Double.MAX_VALUE;
	private boolean _in_estimate = false;
	private boolean _isin_estimateSet = false;
	private boolean _in_quotation = false;
	private boolean _isin_quotationSet = false;
	private boolean _in_internal = false;
	private boolean _isin_internalSet = false;
	private int _id_type = Integer.MIN_VALUE;
	private int _status = Integer.MIN_VALUE;
	private int _notification = Integer.MIN_VALUE;
	private Date _created = null;
	private int _creator = Integer.MIN_VALUE;
	private Date _updated = null;
	private int _updator = Integer.MIN_VALUE;
	private boolean _deleted = false;
	private boolean _isdeletedSet = false;
	private Date _deletion_time = null;

	public QuotationItemModel() {
	}

	// get/set
	public int getId() {
		return _id;
	}

	public void setId(int value) {
		_id = value;
	}

	public String getIdToString() {
		if (_id == Integer.MIN_VALUE || _id == Integer.MAX_VALUE) {
			return "";
		} else {
			return Integer.toString(_id);
		}
	}

	public int getIdQuotation() {
		return _id_quotation;
	}

	public void setIdQuotation(int value) {
		_id_quotation = value;
	}

	public String getIdQuotationToString() {
		if (_id_quotation == Integer.MIN_VALUE
				|| _id_quotation == Integer.MAX_VALUE) {
			return "";
		} else {
			return Integer.toString(_id_quotation);
		}
	}

	public int getIdParent() {
		return _id_parent;
	}

	public void setIdParent(int value) {
		_id_parent = value;
	}

	public String getIdParentToString() {
		if (_id_parent == Integer.MIN_VALUE || _id_parent == Integer.MAX_VALUE) {
			return "";
		} else {
			return Integer.toString(_id_parent);
		}
	}

	public String getCode() {
		return _code;
	}

	public void setCode(String value) {
		_code = value;
	}

	public String getCodeToString() {
		if (_code != null) {
			return HtmlUtil.genHtml(_code);
		} else {
			return "";
		}
	}

	public String getName() {
		return _name;
	}

	public void setName(String value) {
		_name = value;
	}

	public String getNameToString() {
		if (_name != null) {
			return HtmlUtil.genHtml(_name);
		} else {
			return "";
		}
	}

	public String getDescription() {
		return _description;
	}

	public void setDescription(String value) {
		_description = value;
	}

	public String getDescriptionToString() {
		if (_description != null) {
			return HtmlUtil.genHtml(_description);
		} else {
			return "";
		}
	}

	public String getRemark() {
		return _remark;
	}

	public void setRemark(String value) {
		_remark = value;
	}

	public String getRemarkToString() {
		if (_remark != null) {
			return HtmlUtil.genHtml(_remark);
		} else {
			return "";
		}
	}

	public boolean getIsGroup() {
		return _is_group;
	}

	public void setIsGroup(boolean value) {
		_is_group = value;
		_isis_groupSet = true;
	}

	public boolean getIsGroupSet() {
		return _isis_groupSet;
	}

	public void setIsGroupSet(boolean value) {
		_isis_groupSet = value;
	}

	public String getIsGroupToString() {
		if (_isis_groupSet) {
			return HtmlUtil.genHtml(_is_group);
		} else {
			return "";
		}
	}

	public int getIndex() {
		return _index;
	}

	public void setIndex(int value) {
		_index = value;
	}

	public String getIndexToString() {
		if (_index == Integer.MIN_VALUE || _index == Integer.MAX_VALUE) {
			return "";
		} else {
			return Integer.toString(_index);
		}
	}

	public String getDisplayIndex() {
		return _display_index;
	}

	public void setDisplayIndex(String value) {
		_display_index = value;
	}

	public String getDisplayIndexToString() {
		if (_display_index != null) {
			return HtmlUtil.genHtml(_display_index);
		} else {
			return "";
		}
	}

	public int getIdProduct() {
		return _id_product;
	}

	public void setIdProduct(int value) {
		_id_product = value;
	}

	public String getIdProductToString() {
		if (_id_product == Integer.MIN_VALUE
				|| _id_product == Integer.MAX_VALUE) {
			return "";
		} else {
			return Integer.toString(_id_product);
		}
	}

	public int getIdService() {
		return _id_service;
	}

	public void setIdService(int value) {
		_id_service = value;
	}

	public String getIdServiceToString() {
		if (_id_service == Integer.MIN_VALUE
				|| _id_service == Integer.MAX_VALUE) {
			return "";
		} else {
			return Integer.toString(_id_service);
		}
	}

	public int getIdUnit() {
		return _id_unit;
	}

	public void setIdUnit(int value) {
		_id_unit = value;
	}

	public String getIdUnitToString() {
		if (_id_unit == Integer.MIN_VALUE || _id_unit == Integer.MAX_VALUE) {
			return "";
		} else {
			return Integer.toString(_id_unit);
		}
	}

	public int getIdCurrency() {
		return _id_currency;
	}

	public void setIdCurrency(int value) {
		_id_currency = value;
	}

	public String getIdCurrencyToString() {
		if (_id_currency == Integer.MIN_VALUE
				|| _id_currency == Integer.MAX_VALUE) {
			return "";
		} else {
			return Integer.toString(_id_currency);
		}
	}

	public int getEstimateQuantity() {
		return _estimate_quantity;
	}

	public void setEstimateQuantity(int value) {
		_estimate_quantity = value;
	}

	public String getEstimateQuantityToString() {
		if (_estimate_quantity == Integer.MIN_VALUE
				|| _estimate_quantity == Integer.MAX_VALUE) {
			return "";
		} else {
			return Integer.toString(_estimate_quantity);
		}
	}

	public int getQuotationQuantity() {
		return _quotation_quantity;
	}

	public void setQuotationQuantity(int value) {
		_quotation_quantity = value;
	}

	public String getQuotationQuantityToString() {
		if (_quotation_quantity == Integer.MIN_VALUE
				|| _quotation_quantity == Integer.MAX_VALUE) {
			return "";
		} else {
			return Integer.toString(_quotation_quantity);
		}
	}

	public int getInternalQuantity() {
		return _internal_quantity;
	}

	public void setInternalQuantity(int value) {
		_internal_quantity = value;
	}

	public String getInternalQuantityToString() {
		if (_internal_quantity == Integer.MIN_VALUE
				|| _internal_quantity == Integer.MAX_VALUE) {
			return "";
		} else {
			return Integer.toString(_internal_quantity);
		}
	}

	public double getEstimateUnitCost() {
		return _estimate_unit_cost;
	}

	public void setEstimateUnitCost(double value) {
		_estimate_unit_cost = value;
	}

	public String getEstimateUnitCostToString() {
		if (_estimate_unit_cost == Double.MIN_VALUE
				|| _estimate_unit_cost == Double.MAX_VALUE) {
			return "";
		} else {
			return StringUtil.toString(_estimate_unit_cost);
		}
	}

	public double getQuotationUnitCost() {
		return _quotation_unit_cost;
	}

	public void setQuotationUnitCost(double value) {
		_quotation_unit_cost = value;
	}

	public String getQuotationUnitCostToString() {
		if (_quotation_unit_cost == Double.MIN_VALUE
				|| _quotation_unit_cost == Double.MAX_VALUE) {
			return "";
		} else {
			return StringUtil.toString(_quotation_unit_cost);
		}
	}

	public double getInternalUnitCost() {
		return _internal_unit_cost;
	}

	public void setInternalUnitCost(double value) {
		_internal_unit_cost = value;
	}

	public String getInternalUnitCostToString() {
		if (_internal_unit_cost == Double.MIN_VALUE
				|| _internal_unit_cost == Double.MAX_VALUE) {
			return "";
		} else {
			return StringUtil.toString(_internal_unit_cost);
		}
	}

	public double getEstimateTotalAmount() {
		return _estimate_total_amount;
	}

	public void setEstimateTotalAmount(double value) {
		_estimate_total_amount = value;
	}

	public String getEstimateTotalAmountToString() {
		if (_estimate_total_amount == Double.MIN_VALUE
				|| _estimate_total_amount == Double.MAX_VALUE) {
			return "";
		} else {
			return StringUtil.toString(_estimate_total_amount);
		}
	}

	public double getQuotationTotalAmount() {
		return _quotation_total_amount;
	}

	public void setQuotationTotalAmount(double value) {
		_quotation_total_amount = value;
	}

	public String getQuotationTotalAmountToString() {
		if (_quotation_total_amount == Double.MIN_VALUE
				|| _quotation_total_amount == Double.MAX_VALUE) {
			return "";
		} else {
			return StringUtil.toString(_quotation_total_amount);
		}
	}

	public double getInternalTotalAmount() {
		return _internal_total_amount;
	}

	public void setInternalTotalAmount(double value) {
		_internal_total_amount = value;
	}

	public String getInternalTotalAmountToString() {
		if (_internal_total_amount == Double.MIN_VALUE
				|| _internal_total_amount == Double.MAX_VALUE) {
			return "";
		} else {
			return StringUtil.toString(_internal_total_amount);
		}
	}

	public boolean getInEstimate() {
		return _in_estimate;
	}

	public void setInEstimate(boolean value) {
		_in_estimate = value;
		_isin_estimateSet = true;
	}

	public boolean getInEstimateSet() {
		return _isin_estimateSet;
	}

	public String getInEstimateToString() {
		if (_isin_estimateSet) {
			return HtmlUtil.genHtml(_in_estimate);
		} else {
			return "";
		}
	}

	public boolean getInQuotation() {
		return _in_quotation;
	}

	public void setInQuotation(boolean value) {
		_in_quotation = value;
		_isin_quotationSet = true;
	}

	public boolean getInQuotationSet() {
		return _isin_quotationSet;
	}

	public String getInQuotationToString() {
		if (_isin_quotationSet) {
			return HtmlUtil.genHtml(_in_quotation);
		} else {
			return "";
		}
	}

	public boolean getInInternal() {
		return _in_internal;
	}

	public void setInInternal(boolean value) {
		_in_internal = value;
		_isin_internalSet = true;
	}

	public boolean getInInternalSet() {
		return _isin_internalSet;
	}

	public String getInInternalToString() {
		if (_isin_internalSet) {
			return HtmlUtil.genHtml(_in_internal);
		} else {
			return "";
		}
	}

	public int getIdType() {
		return _id_type;
	}

	public void setIdType(int value) {
		_id_type = value;
	}

	public String getIdTypeToString() {
		if (_id_type == Integer.MIN_VALUE || _id_type == Integer.MAX_VALUE) {
			return "";
		} else {
			return Integer.toString(_id_type);
		}
	}

	public int getStatus() {
		return _status;
	}

	public void setStatus(int value) {
		_status = value;
	}

	public String getStatusToString() {
		if (_status == Integer.MIN_VALUE || _status == Integer.MAX_VALUE) {
			return "";
		} else {
			return Integer.toString(_status);
		}
	}

	public int getNotification() {
		return _notification;
	}

	public void setNotification(int value) {
		_notification = value;
	}

	public String getNotificationToString() {
		if (_notification == Integer.MIN_VALUE
				|| _notification == Integer.MAX_VALUE) {
			return "";
		} else {
			return Integer.toString(_notification);
		}
	}

	public Date getCreated() {
		return _created;
	}

	public void setCreated(Date value) {
		_created = value;
	}

	public String getCreatedToString() {
		if (_created != null) {
			return StringUtil.toDateTimeString(_created);
		} else {
			return "";
		}
	}

	public int getCreator() {
		return _creator;
	}

	public void setCreator(int value) {
		_creator = value;
	}

	public String getCreatorToString() {
		if (_creator == Integer.MIN_VALUE || _creator == Integer.MAX_VALUE) {
			return "";
		} else {
			return Integer.toString(_creator);
		}
	}

	public Date getUpdated() {
		return _updated;
	}

	public void setUpdated(Date value) {
		_updated = value;
	}

	public String getUpdatedToString() {
		if (_updated != null) {
			return StringUtil.toDateTimeString(_updated);
		} else {
			return "";
		}
	}

	public int getUpdator() {
		return _updator;
	}

	public void setUpdator(int value) {
		_updator = value;
	}

	public String getUpdatorToString() {
		if (_updator == Integer.MIN_VALUE || _updator == Integer.MAX_VALUE) {
			return "";
		} else {
			return Integer.toString(_updator);
		}
	}

	public boolean getDeleted() {
		return _deleted;
	}

	public void setDeleted(boolean value) {
		_deleted = value;
		_isdeletedSet = true;
	}

	public boolean getDeletedSet() {
		return _isdeletedSet;
	}

	public String getDeletedToString() {
		if (_isdeletedSet) {
			return HtmlUtil.genHtml(_deleted);
		} else {
			return "";
		}
	}

	public Date getDeletionTime() {
		return _deletion_time;
	}

	public void setDeletionTime(Date value) {
		_deletion_time = value;
	}

	public String getDeletionTimeToString() {
		if (_deletion_time != null) {
			return StringUtil.toDateTimeString(_deletion_time);
		} else {
			return "";
		}
	}

	@Override
	public int[] getPrimaryKey() {
		int[] ids = new int[1];
		ids[0] = getId();
		return ids;
	}

	@Override
	public IModel readFromResultSet(ResultSet rs) throws SQLException {
		QuotationItemModel model = null;

		model = new QuotationItemModel();

		// read fields
		{
			int value = rs.getInt("id");
			if (!rs.wasNull()) {
				model.setId(value);
			}
		}
		{
			int value = rs.getInt("id_quotation");
			if (!rs.wasNull()) {
				model.setIdQuotation(value);
			}
		}
		{
			int value = rs.getInt("id_parent");
			if (!rs.wasNull()) {
				model.setIdParent(value);
			}
		}
		{
			String value = rs.getString("code");
			if (!rs.wasNull()) {
				model.setCode(value);
			}
		}
		{
			String value = rs.getString("name");
			if (!rs.wasNull()) {
				model.setName(value);
			}
		}
		{
			String value = rs.getString("description");
			if (!rs.wasNull()) {
				model.setDescription(value);
			}
		}
		{
			String value = rs.getString("remark");
			if (!rs.wasNull()) {
				model.setRemark(value);
			}
		}
		{
			boolean value = rs.getBoolean("is_group");
			if (!rs.wasNull()) {
				model.setIsGroup(value);
			}
		}
		{
			int value = rs.getInt("index");
			if (!rs.wasNull()) {
				model.setIndex(value);
			}
		}
		{
			String value = rs.getString("display_index");
			if (!rs.wasNull()) {
				model.setDisplayIndex(value);
			}
		}
		{
			int value = rs.getInt("id_product");
			if (!rs.wasNull()) {
				model.setIdProduct(value);
			}
		}
		{
			int value = rs.getInt("id_service");
			if (!rs.wasNull()) {
				model.setIdService(value);
			}
		}
		{
			int value = rs.getInt("id_unit");
			if (!rs.wasNull()) {
				model.setIdUnit(value);
			}
		}
		{
			int value = rs.getInt("id_currency");
			if (!rs.wasNull()) {
				model.setIdCurrency(value);
			}
		}
		{
			int value = rs.getInt("estimate_quantity");
			if (!rs.wasNull()) {
				model.setEstimateQuantity(value);
			}
		}
		{
			int value = rs.getInt("quotation_quantity");
			if (!rs.wasNull()) {
				model.setQuotationQuantity(value);
			}
		}
		{
			int value = rs.getInt("internal_quantity");
			if (!rs.wasNull()) {
				model.setInternalQuantity(value);
			}
		}
		{
			double value = rs.getDouble("estimate_unit_cost");
			if (!rs.wasNull()) {
				model.setEstimateUnitCost(value);
			}
		}
		{
			double value = rs.getDouble("quotation_unit_cost");
			if (!rs.wasNull()) {
				model.setQuotationUnitCost(value);
			}
		}
		{
			double value = rs.getDouble("internal_unit_cost");
			if (!rs.wasNull()) {
				model.setInternalUnitCost(value);
			}
		}
		{
			double value = rs.getDouble("estimate_total_amount");
			if (!rs.wasNull()) {
				model.setEstimateTotalAmount(value);
			}
		}
		{
			double value = rs.getDouble("quotation_total_amount");
			if (!rs.wasNull()) {
				model.setQuotationTotalAmount(value);
			}
		}
		{
			double value = rs.getDouble("internal_total_amount");
			if (!rs.wasNull()) {
				model.setInternalTotalAmount(value);
			}
		}
		{
			boolean value = rs.getBoolean("in_estimate");
			if (!rs.wasNull()) {
				model.setInEstimate(value);
			}
		}
		{
			boolean value = rs.getBoolean("in_quotation");
			if (!rs.wasNull()) {
				model.setInQuotation(value);
			}
		}
		{
			boolean value = rs.getBoolean("in_internal");
			if (!rs.wasNull()) {
				model.setInInternal(value);
			}
		}
		{
			int value = rs.getInt("id_type");
			if (!rs.wasNull()) {
				model.setIdType(value);
			}
		}
		{
			int value = rs.getInt("status");
			if (!rs.wasNull()) {
				model.setStatus(value);
			}
		}
		{
			int value = rs.getInt("notification");
			if (!rs.wasNull()) {
				model.setNotification(value);
			}
		}
		{
			Date value = rs.getTimestamp("created");
			if (!rs.wasNull()) {
				model.setCreated(value);
			}
		}
		{
			int value = rs.getInt("creator");
			if (!rs.wasNull()) {
				model.setCreator(value);
			}
		}
		{
			Date value = rs.getTimestamp("updated");
			if (!rs.wasNull()) {
				model.setUpdated(value);
			}
		}
		{
			int value = rs.getInt("updator");
			if (!rs.wasNull()) {
				model.setUpdator(value);
			}
		}
		{
			boolean value = rs.getBoolean("deleted");
			if (!rs.wasNull()) {
				model.setDeleted(value);
			}
		}
		{
			Date value = rs.getTimestamp("deletion_time");
			if (!rs.wasNull()) {
				model.setDeletionTime(value);
			}
		}

		return model;
	}

	@Override
	public PreparedStatement genSelectStatement(Connection dbConn, IModel query)
			throws SQLException {
		String sql = "SELECT * FROM sp_quotation_item_select(:id);";
		NamedParameterPreparedStatement st = new NamedParameterPreparedStatement(
				dbConn, sql);

		QuotationItemModel obj = (QuotationItemModel) query;

		// set parameters
		st.setObject("id", obj.getId());

		return st.getPreparedStatement();
	}

	@Override
	public PreparedStatement genSelectListStatement(Connection dbConn,
			IModelExt query) throws SQLException {
		String sql = "SELECT * FROM sp_quotation_item_selectList(:limit, :offset, :id,:id_quotation,:id_parent,:code,:name,:description,:remark,:is_group,:index,:display_index,:id_product,:id_service,:id_unit,:id_currency,:estimate_quantity,:quotation_quantity,:internal_quantity,:estimate_unit_cost,:quotation_unit_cost,:internal_unit_cost,:estimate_total_amount,:quotation_total_amount,:internal_total_amount,:in_estimate,:in_quotation,:in_internal,:id_type,:status,:notification,:createdFrom,:createdTo,:creator,:updatedFrom,:updatedTo,:updator,:deleted,:deletion_timeFrom,:deletion_timeTo)";

		NamedParameterPreparedStatement st = new NamedParameterPreparedStatement(
				dbConn, sql);

		QuotationItemModelExt obj = (QuotationItemModelExt) query;

		if (obj.getLimit() != Integer.MIN_VALUE) {
			st.setObject("limit", obj.getLimit());
		} else {
			st.setObject("limit", Integer.MAX_VALUE);
		}
		if (obj.getOffset() != Integer.MIN_VALUE) {
			st.setObject("offset", obj.getOffset());
		} else {
			st.setObject("offset", 0);
		}

		// set parameters
		if (obj.getId() != Integer.MIN_VALUE) {
			st.setObject("id", obj.getId());
		} else {
			st.setObject("id", null);
		}
		if (obj.getIdQuotation() != Integer.MIN_VALUE) {
			st.setObject("id_quotation", obj.getIdQuotation());
		} else {
			st.setObject("id_quotation", null);
		}
		if (obj.getIdParent() != Integer.MIN_VALUE) {
			st.setObject("id_parent", obj.getIdParent());
		} else {
			st.setObject("id_parent", null);
		}
		if (obj.getCode() != null) {
			st.setObject("code", obj.getCode());
		} else {
			st.setObject("code", null);
		}
		if (obj.getName() != null) {
			st.setObject("name", obj.getName());
		} else {
			st.setObject("name", null);
		}
		if (obj.getDescription() != null) {
			st.setObject("description", obj.getDescription());
		} else {
			st.setObject("description", null);
		}
		if (obj.getRemark() != null) {
			st.setObject("remark", obj.getRemark());
		} else {
			st.setObject("remark", null);
		}
		if (obj.getIsGroupSet()) {
			st.setObject("is_group", obj.getIsGroup());
		} else {
			st.setObject("is_group", null);
		}
		if (obj.getIndex() != Integer.MIN_VALUE) {
			st.setObject("index", obj.getIndex());
		} else {
			st.setObject("index", null);
		}
		if (obj.getDisplayIndex() != null) {
			st.setObject("display_index", obj.getDisplayIndex());
		} else {
			st.setObject("display_index", null);
		}
		if (obj.getIdProduct() != Integer.MIN_VALUE) {
			st.setObject("id_product", obj.getIdProduct());
		} else {
			st.setObject("id_product", null);
		}
		if (obj.getIdService() != Integer.MIN_VALUE) {
			st.setObject("id_service", obj.getIdService());
		} else {
			st.setObject("id_service", null);
		}
		if (obj.getIdUnit() != Integer.MIN_VALUE) {
			st.setObject("id_unit", obj.getIdUnit());
		} else {
			st.setObject("id_unit", null);
		}
		if (obj.getIdCurrency() != Integer.MIN_VALUE) {
			st.setObject("id_currency", obj.getIdCurrency());
		} else {
			st.setObject("id_currency", null);
		}
		if (obj.getEstimateQuantity() != Integer.MIN_VALUE) {
			st.setObject("estimate_quantity", obj.getEstimateQuantity());
		} else {
			st.setObject("estimate_quantity", null);
		}
		if (obj.getQuotationQuantity() != Integer.MIN_VALUE) {
			st.setObject("quotation_quantity", obj.getQuotationQuantity());
		} else {
			st.setObject("quotation_quantity", null);
		}
		if (obj.getInternalQuantity() != Integer.MIN_VALUE) {
			st.setObject("internal_quantity", obj.getInternalQuantity());
		} else {
			st.setObject("internal_quantity", null);
		}
		if (obj.getEstimateUnitCost() != Double.MAX_VALUE) {
			st.setObject("estimate_unit_cost", obj.getEstimateUnitCost());
		} else {
			st.setObject("estimate_unit_cost", null);
		}
		if (obj.getQuotationUnitCost() != Double.MAX_VALUE) {
			st.setObject("quotation_unit_cost", obj.getQuotationUnitCost());
		} else {
			st.setObject("quotation_unit_cost", null);
		}
		if (obj.getInternalUnitCost() != Double.MAX_VALUE) {
			st.setObject("internal_unit_cost", obj.getInternalUnitCost());
		} else {
			st.setObject("internal_unit_cost", null);
		}
		if (obj.getEstimateTotalAmount() != Double.MAX_VALUE) {
			st.setObject("estimate_total_amount", obj.getEstimateTotalAmount());
		} else {
			st.setObject("estimate_total_amount", null);
		}
		if (obj.getQuotationTotalAmount() != Double.MAX_VALUE) {
			st.setObject("quotation_total_amount",
					obj.getQuotationTotalAmount());
		} else {
			st.setObject("quotation_total_amount", null);
		}
		if (obj.getInternalTotalAmount() != Double.MAX_VALUE) {
			st.setObject("internal_total_amount", obj.getInternalTotalAmount());
		} else {
			st.setObject("internal_total_amount", null);
		}
		if (obj.getInEstimateSet()) {
			st.setObject("in_estimate", obj.getInEstimate());
		} else {
			st.setObject("in_estimate", null);
		}
		if (obj.getInQuotationSet()) {
			st.setObject("in_quotation", obj.getInQuotation());
		} else {
			st.setObject("in_quotation", null);
		}
		if (obj.getInInternalSet()) {
			st.setObject("in_internal", obj.getInInternal());
		} else {
			st.setObject("in_internal", null);
		}
		if (obj.getIdType() != Integer.MIN_VALUE) {
			st.setObject("id_type", obj.getIdType());
		} else {
			st.setObject("id_type", null);
		}
		if (obj.getStatus() != Integer.MIN_VALUE) {
			st.setObject("status", obj.getStatus());
		} else {
			st.setObject("status", null);
		}
		if (obj.getNotification() != Integer.MIN_VALUE) {
			st.setObject("notification", obj.getNotification());
		} else {
			st.setObject("notification", null);
		}
		if (obj.getCreatedFrom() != null) {
			st.setObject("createdFrom", obj.getCreatedFrom());
		} else {
			st.setObject("createdFrom", null);
		}
		if (obj.getCreatedTo() != null) {
			st.setObject("createdTo", obj.getCreatedTo());
		} else {
			st.setObject("createdTo", null);
		}
		if (obj.getCreator() != Integer.MIN_VALUE) {
			st.setObject("creator", obj.getCreator());
		} else {
			st.setObject("creator", null);
		}
		if (obj.getUpdatedFrom() != null) {
			st.setObject("updatedFrom", obj.getUpdatedFrom());
		} else {
			st.setObject("updatedFrom", null);
		}
		if (obj.getUpdatedTo() != null) {
			st.setObject("updatedTo", obj.getUpdatedTo());
		} else {
			st.setObject("updatedTo", null);
		}
		if (obj.getUpdator() != Integer.MIN_VALUE) {
			st.setObject("updator", obj.getUpdator());
		} else {
			st.setObject("updator", null);
		}
		if (obj.getDeletedSet()) {
			st.setObject("deleted", obj.getDeleted());
		} else {
			st.setObject("deleted", null);
		}
		if (obj.getDeletionTimeFrom() != null) {
			st.setObject("deletion_timeFrom", obj.getDeletionTimeFrom());
		} else {
			st.setObject("deletion_timeFrom", null);
		}
		if (obj.getDeletionTimeTo() != null) {
			st.setObject("deletion_timeTo", obj.getDeletionTimeTo());
		} else {
			st.setObject("deletion_timeTo", null);
		}

		return st.getPreparedStatement();
	}

	@Override
	public PreparedStatement genInsertStatement(Connection dbConn, IModel model)
			throws SQLException {
		String sql = "SELECT sp_quotation_item_insert(:id_quotation,:id_parent,:code,:name,:description,:remark,:is_group,:index,:display_index,:id_product,:id_service,:id_unit,:id_currency,:estimate_quantity,:quotation_quantity,:internal_quantity,:estimate_unit_cost,:quotation_unit_cost,:internal_unit_cost,:estimate_total_amount,:quotation_total_amount,:internal_total_amount,:in_estimate,:in_quotation,:in_internal,:id_type,:status,:notification,:creator)";
		NamedParameterPreparedStatement st = new NamedParameterPreparedStatement(
				dbConn, sql);

		QuotationItemModel obj = (QuotationItemModel) model;

		// set parameters here
		if (obj.getIdQuotation() != Integer.MIN_VALUE) {
			st.setObject("id_quotation", obj.getIdQuotation());
		} else {
			st.setObject("id_quotation", null);
		}
		if (obj.getIdParent() != Integer.MIN_VALUE) {
			st.setObject("id_parent", obj.getIdParent());
		} else {
			st.setObject("id_parent", null);
		}
		if (obj.getCode() != null) {
			st.setObject("code", obj.getCode());
		} else {
			st.setObject("code", null);
		}
		if (obj.getName() != null) {
			st.setObject("name", obj.getName());
		} else {
			st.setObject("name", null);
		}
		if (obj.getDescription() != null) {
			st.setObject("description", obj.getDescription());
		} else {
			st.setObject("description", null);
		}
		if (obj.getRemark() != null) {
			st.setObject("remark", obj.getRemark());
		} else {
			st.setObject("remark", null);
		}
		if (obj.getIsGroupSet()) {
			st.setObject("is_group", obj.getIsGroup());
		} else {
			st.setObject("is_group", null);
		}
		if (obj.getIndex() != Integer.MIN_VALUE) {
			st.setObject("index", obj.getIndex());
		} else {
			st.setObject("index", null);
		}
		if (obj.getDisplayIndex() != null) {
			st.setObject("display_index", obj.getDisplayIndex());
		} else {
			st.setObject("display_index", null);
		}
		if (obj.getIdProduct() != Integer.MIN_VALUE) {
			st.setObject("id_product", obj.getIdProduct());
		} else {
			st.setObject("id_product", null);
		}
		if (obj.getIdService() != Integer.MIN_VALUE) {
			st.setObject("id_service", obj.getIdService());
		} else {
			st.setObject("id_service", null);
		}
		if (obj.getIdUnit() != Integer.MIN_VALUE) {
			st.setObject("id_unit", obj.getIdUnit());
		} else {
			st.setObject("id_unit", null);
		}
		if (obj.getIdCurrency() != Integer.MIN_VALUE) {
			st.setObject("id_currency", obj.getIdCurrency());
		} else {
			st.setObject("id_currency", null);
		}
		if (obj.getEstimateQuantity() != Integer.MIN_VALUE) {
			st.setObject("estimate_quantity", obj.getEstimateQuantity());
		} else {
			st.setObject("estimate_quantity", null);
		}
		if (obj.getQuotationQuantity() != Integer.MIN_VALUE) {
			st.setObject("quotation_quantity", obj.getQuotationQuantity());
		} else {
			st.setObject("quotation_quantity", null);
		}
		if (obj.getInternalQuantity() != Integer.MIN_VALUE) {
			st.setObject("internal_quantity", obj.getInternalQuantity());
		} else {
			st.setObject("internal_quantity", null);
		}
		if (obj.getEstimateUnitCost() != Double.MAX_VALUE) {
			st.setObject("estimate_unit_cost", obj.getEstimateUnitCost());
		} else {
			st.setObject("estimate_unit_cost", null);
		}
		if (obj.getQuotationUnitCost() != Double.MAX_VALUE) {
			st.setObject("quotation_unit_cost", obj.getQuotationUnitCost());
		} else {
			st.setObject("quotation_unit_cost", null);
		}
		if (obj.getInternalUnitCost() != Double.MAX_VALUE) {
			st.setObject("internal_unit_cost", obj.getInternalUnitCost());
		} else {
			st.setObject("internal_unit_cost", null);
		}
		if (obj.getEstimateTotalAmount() != Double.MAX_VALUE) {
			st.setObject("estimate_total_amount", obj.getEstimateTotalAmount());
		} else {
			st.setObject("estimate_total_amount", null);
		}
		if (obj.getQuotationTotalAmount() != Double.MAX_VALUE) {
			st.setObject("quotation_total_amount",
					obj.getQuotationTotalAmount());
		} else {
			st.setObject("quotation_total_amount", null);
		}
		if (obj.getInternalTotalAmount() != Double.MAX_VALUE) {
			st.setObject("internal_total_amount", obj.getInternalTotalAmount());
		} else {
			st.setObject("internal_total_amount", null);
		}
		if (obj.getInEstimateSet()) {
			st.setObject("in_estimate", obj.getInEstimate());
		} else {
			st.setObject("in_estimate", null);
		}
		if (obj.getInQuotationSet()) {
			st.setObject("in_quotation", obj.getInQuotation());
		} else {
			st.setObject("in_quotation", null);
		}
		if (obj.getInInternalSet()) {
			st.setObject("in_internal", obj.getInInternal());
		} else {
			st.setObject("in_internal", null);
		}
		if (obj.getIdType() != Integer.MIN_VALUE) {
			st.setObject("id_type", obj.getIdType());
		} else {
			st.setObject("id_type", null);
		}
		if (obj.getStatus() != Integer.MIN_VALUE) {
			st.setObject("status", obj.getStatus());
		} else {
			st.setObject("status", null);
		}
		if (obj.getNotification() != Integer.MIN_VALUE) {
			st.setObject("notification", obj.getNotification());
		} else {
			st.setObject("notification", null);
		}
		if (obj.getCreator() != Integer.MIN_VALUE) {
			st.setObject("creator", obj.getCreator());
		} else {
			st.setObject("creator", null);
		}

		return st.getPreparedStatement();
	}

	@Override
	public PreparedStatement genUpdateStatement(Connection dbConn, IModel model)
			throws SQLException {
		String sql = "SELECT sp_quotation_item_update(:id,:id_quotation,:id_parent,:code,:name,:description,:remark,:is_group,:index,:display_index,:id_product,:id_service,:id_unit,:id_currency,:estimate_quantity,:quotation_quantity,:internal_quantity,:estimate_unit_cost,:quotation_unit_cost,:internal_unit_cost,:estimate_total_amount,:quotation_total_amount,:internal_total_amount,:in_estimate,:in_quotation,:in_internal,:id_type,:status,:notification,:updator,:deleted,:deletion_time)";

		NamedParameterPreparedStatement st = new NamedParameterPreparedStatement(
				dbConn, sql);

		QuotationItemModel obj = (QuotationItemModel) model;

		// set parameters here
		if (obj.getId() != Integer.MIN_VALUE) {
			st.setObject("id", obj.getId());
		} else {
			st.setObject("id", null);
		}
		if (obj.getIdQuotation() != Integer.MIN_VALUE) {
			st.setObject("id_quotation", obj.getIdQuotation());
		} else {
			st.setObject("id_quotation", null);
		}
		if (obj.getIdParent() != Integer.MIN_VALUE) {
			st.setObject("id_parent", obj.getIdParent());
		} else {
			st.setObject("id_parent", null);
		}
		if (obj.getCode() != null) {
			st.setObject("code", obj.getCode());
		} else {
			st.setObject("code", null);
		}
		if (obj.getName() != null) {
			st.setObject("name", obj.getName());
		} else {
			st.setObject("name", null);
		}
		if (obj.getDescription() != null) {
			st.setObject("description", obj.getDescription());
		} else {
			st.setObject("description", null);
		}
		if (obj.getRemark() != null) {
			st.setObject("remark", obj.getRemark());
		} else {
			st.setObject("remark", null);
		}
		if (obj.getIsGroupSet()) {
			st.setObject("is_group", obj.getIsGroup());
		} else {
			st.setObject("is_group", null);
		}
		if (obj.getIndex() != Integer.MIN_VALUE) {
			st.setObject("index", obj.getIndex());
		} else {
			st.setObject("index", null);
		}
		if (obj.getDisplayIndex() != null) {
			st.setObject("display_index", obj.getDisplayIndex());
		} else {
			st.setObject("display_index", null);
		}
		if (obj.getIdProduct() != Integer.MIN_VALUE) {
			st.setObject("id_product", obj.getIdProduct());
		} else {
			st.setObject("id_product", null);
		}
		if (obj.getIdService() != Integer.MIN_VALUE) {
			st.setObject("id_service", obj.getIdService());
		} else {
			st.setObject("id_service", null);
		}
		if (obj.getIdUnit() != Integer.MIN_VALUE) {
			st.setObject("id_unit", obj.getIdUnit());
		} else {
			st.setObject("id_unit", null);
		}
		if (obj.getIdCurrency() != Integer.MIN_VALUE) {
			st.setObject("id_currency", obj.getIdCurrency());
		} else {
			st.setObject("id_currency", null);
		}
		if (obj.getEstimateQuantity() != Integer.MIN_VALUE) {
			st.setObject("estimate_quantity", obj.getEstimateQuantity());
		} else {
			st.setObject("estimate_quantity", null);
		}
		if (obj.getQuotationQuantity() != Integer.MIN_VALUE) {
			st.setObject("quotation_quantity", obj.getQuotationQuantity());
		} else {
			st.setObject("quotation_quantity", null);
		}
		if (obj.getInternalQuantity() != Integer.MIN_VALUE) {
			st.setObject("internal_quantity", obj.getInternalQuantity());
		} else {
			st.setObject("internal_quantity", null);
		}
		if (obj.getEstimateUnitCost() != Double.MAX_VALUE) {
			st.setObject("estimate_unit_cost", obj.getEstimateUnitCost());
		} else {
			st.setObject("estimate_unit_cost", null);
		}
		if (obj.getQuotationUnitCost() != Double.MAX_VALUE) {
			st.setObject("quotation_unit_cost", obj.getQuotationUnitCost());
		} else {
			st.setObject("quotation_unit_cost", null);
		}
		if (obj.getInternalUnitCost() != Double.MAX_VALUE) {
			st.setObject("internal_unit_cost", obj.getInternalUnitCost());
		} else {
			st.setObject("internal_unit_cost", null);
		}
		if (obj.getEstimateTotalAmount() != Double.MAX_VALUE) {
			st.setObject("estimate_total_amount", obj.getEstimateTotalAmount());
		} else {
			st.setObject("estimate_total_amount", null);
		}
		if (obj.getQuotationTotalAmount() != Double.MAX_VALUE) {
			st.setObject("quotation_total_amount",
					obj.getQuotationTotalAmount());
		} else {
			st.setObject("quotation_total_amount", null);
		}
		if (obj.getInternalTotalAmount() != Double.MAX_VALUE) {
			st.setObject("internal_total_amount", obj.getInternalTotalAmount());
		} else {
			st.setObject("internal_total_amount", null);
		}
		if (obj.getInEstimateSet()) {
			st.setObject("in_estimate", obj.getInEstimate());
		} else {
			st.setObject("in_estimate", null);
		}
		if (obj.getInQuotationSet()) {
			st.setObject("in_quotation", obj.getInQuotation());
		} else {
			st.setObject("in_quotation", null);
		}
		if (obj.getInInternalSet()) {
			st.setObject("in_internal", obj.getInInternal());
		} else {
			st.setObject("in_internal", null);
		}
		if (obj.getIdType() != Integer.MIN_VALUE) {
			st.setObject("id_type", obj.getIdType());
		} else {
			st.setObject("id_type", null);
		}
		if (obj.getStatus() != Integer.MIN_VALUE) {
			st.setObject("status", obj.getStatus());
		} else {
			st.setObject("status", null);
		}
		if (obj.getNotification() != Integer.MIN_VALUE) {
			st.setObject("notification", obj.getNotification());
		} else {
			st.setObject("notification", null);
		}
		if (obj.getUpdator() != Integer.MIN_VALUE) {
			st.setObject("updator", obj.getUpdator());
		} else {
			st.setObject("updator", null);
		}
		if (obj.getDeletedSet()) {
			st.setObject("deleted", obj.getDeleted());
		} else {
			st.setObject("deleted", null);
		}
		if (obj.getDeletionTime() != null) {
			st.setObject("deletion_time", obj.getDeletionTime());
		} else {
			st.setObject("deletion_time", null);
		}

		return st.getPreparedStatement();
	}

	@Override
	public PreparedStatement genDeleteStatement(Connection dbConn, IModel query)
			throws SQLException {
		String sql = "select sp_quotation_item_delete(:id);";
		NamedParameterPreparedStatement st = new NamedParameterPreparedStatement(
				dbConn, sql);

		QuotationItemModel obj = (QuotationItemModel) query;

		// set primary keys
		st.setObject("id", obj.getId());

		return st.getPreparedStatement();
	}

	@Override
	public PreparedStatement genCountStatement(Connection dbConn,
			IModelExt input) throws SQLException {
		String sql = "SELECT sp_quotation_item_count(:id,:id_quotation,:id_parent,:code,:name,:description,:remark,:is_group,:index,:display_index,:id_product,:id_service,:id_unit,:id_currency,:estimate_quantity,:quotation_quantity,:internal_quantity,:estimate_unit_cost,:quotation_unit_cost,:internal_unit_cost,:estimate_total_amount,:quotation_total_amount,:internal_total_amount,:in_estimate,:in_quotation,:in_internal,:id_type,:status,:notification,:createdFrom,:createdTo,:creator,:updatedFrom,:updatedTo,:updator,:deleted,:deletion_timeFrom,:deletion_timeTo)";

		NamedParameterPreparedStatement st = new NamedParameterPreparedStatement(
				dbConn, sql);

		QuotationItemModelExt obj = (QuotationItemModelExt) input;

		// set parameters here
		if (obj.getId() != Integer.MIN_VALUE) {
			st.setObject("id", obj.getId());
		} else {
			st.setObject("id", null);
		}
		if (obj.getIdQuotation() != Integer.MIN_VALUE) {
			st.setObject("id_quotation", obj.getIdQuotation());
		} else {
			st.setObject("id_quotation", null);
		}
		if (obj.getIdParent() != Integer.MIN_VALUE) {
			st.setObject("id_parent", obj.getIdParent());
		} else {
			st.setObject("id_parent", null);
		}
		if (obj.getCode() != null) {
			st.setObject("code", obj.getCode());
		} else {
			st.setObject("code", null);
		}
		if (obj.getName() != null) {
			st.setObject("name", obj.getName());
		} else {
			st.setObject("name", null);
		}
		if (obj.getDescription() != null) {
			st.setObject("description", obj.getDescription());
		} else {
			st.setObject("description", null);
		}
		if (obj.getRemark() != null) {
			st.setObject("remark", obj.getRemark());
		} else {
			st.setObject("remark", null);
		}
		if (obj.getIsGroupSet()) {
			st.setObject("is_group", obj.getIsGroup());
		} else {
			st.setObject("is_group", null);
		}
		if (obj.getIndex() != Integer.MIN_VALUE) {
			st.setObject("index", obj.getIndex());
		} else {
			st.setObject("index", null);
		}
		if (obj.getDisplayIndex() != null) {
			st.setObject("display_index", obj.getDisplayIndex());
		} else {
			st.setObject("display_index", null);
		}
		if (obj.getIdProduct() != Integer.MIN_VALUE) {
			st.setObject("id_product", obj.getIdProduct());
		} else {
			st.setObject("id_product", null);
		}
		if (obj.getIdService() != Integer.MIN_VALUE) {
			st.setObject("id_service", obj.getIdService());
		} else {
			st.setObject("id_service", null);
		}
		if (obj.getIdUnit() != Integer.MIN_VALUE) {
			st.setObject("id_unit", obj.getIdUnit());
		} else {
			st.setObject("id_unit", null);
		}
		if (obj.getIdCurrency() != Integer.MIN_VALUE) {
			st.setObject("id_currency", obj.getIdCurrency());
		} else {
			st.setObject("id_currency", null);
		}
		if (obj.getEstimateQuantity() != Integer.MIN_VALUE) {
			st.setObject("estimate_quantity", obj.getEstimateQuantity());
		} else {
			st.setObject("estimate_quantity", null);
		}
		if (obj.getQuotationQuantity() != Integer.MIN_VALUE) {
			st.setObject("quotation_quantity", obj.getQuotationQuantity());
		} else {
			st.setObject("quotation_quantity", null);
		}
		if (obj.getInternalQuantity() != Integer.MIN_VALUE) {
			st.setObject("internal_quantity", obj.getInternalQuantity());
		} else {
			st.setObject("internal_quantity", null);
		}
		if (obj.getEstimateUnitCost() != Double.MAX_VALUE) {
			st.setObject("estimate_unit_cost", obj.getEstimateUnitCost());
		} else {
			st.setObject("estimate_unit_cost", null);
		}
		if (obj.getQuotationUnitCost() != Double.MAX_VALUE) {
			st.setObject("quotation_unit_cost", obj.getQuotationUnitCost());
		} else {
			st.setObject("quotation_unit_cost", null);
		}
		if (obj.getInternalUnitCost() != Double.MAX_VALUE) {
			st.setObject("internal_unit_cost", obj.getInternalUnitCost());
		} else {
			st.setObject("internal_unit_cost", null);
		}
		if (obj.getEstimateTotalAmount() != Double.MAX_VALUE) {
			st.setObject("estimate_total_amount", obj.getEstimateTotalAmount());
		} else {
			st.setObject("estimate_total_amount", null);
		}
		if (obj.getQuotationTotalAmount() != Double.MAX_VALUE) {
			st.setObject("quotation_total_amount",
					obj.getQuotationTotalAmount());
		} else {
			st.setObject("quotation_total_amount", null);
		}
		if (obj.getInternalTotalAmount() != Double.MAX_VALUE) {
			st.setObject("internal_total_amount", obj.getInternalTotalAmount());
		} else {
			st.setObject("internal_total_amount", null);
		}
		if (obj.getInEstimateSet()) {
			st.setObject("in_estimate", obj.getInEstimate());
		} else {
			st.setObject("in_estimate", null);
		}
		if (obj.getInQuotationSet()) {
			st.setObject("in_quotation", obj.getInQuotation());
		} else {
			st.setObject("in_quotation", null);
		}
		if (obj.getInInternalSet()) {
			st.setObject("in_internal", obj.getInInternal());
		} else {
			st.setObject("in_internal", null);
		}
		if (obj.getIdType() != Integer.MIN_VALUE) {
			st.setObject("id_type", obj.getIdType());
		} else {
			st.setObject("id_type", null);
		}
		if (obj.getStatus() != Integer.MIN_VALUE) {
			st.setObject("status", obj.getStatus());
		} else {
			st.setObject("status", null);
		}
		if (obj.getNotification() != Integer.MIN_VALUE) {
			st.setObject("notification", obj.getNotification());
		} else {
			st.setObject("notification", null);
		}
		if (obj.getCreatedFrom() != null) {
			st.setObject("createdFrom", obj.getCreatedFrom());
		} else {
			st.setObject("createdFrom", null);
		}
		if (obj.getCreatedTo() != null) {
			st.setObject("createdTo", obj.getCreatedTo());
		} else {
			st.setObject("createdTo", null);
		}
		if (obj.getCreator() != Integer.MIN_VALUE) {
			st.setObject("creator", obj.getCreator());
		} else {
			st.setObject("creator", null);
		}
		if (obj.getUpdatedFrom() != null) {
			st.setObject("updatedFrom", obj.getUpdatedFrom());
		} else {
			st.setObject("updatedFrom", null);
		}
		if (obj.getUpdatedTo() != null) {
			st.setObject("updatedTo", obj.getUpdatedTo());
		} else {
			st.setObject("updatedTo", null);
		}
		if (obj.getUpdator() != Integer.MIN_VALUE) {
			st.setObject("updator", obj.getUpdator());
		} else {
			st.setObject("updator", null);
		}
		if (obj.getDeletedSet()) {
			st.setObject("deleted", obj.getDeleted());
		} else {
			st.setObject("deleted", null);
		}
		if (obj.getDeletionTimeFrom() != null) {
			st.setObject("deletion_timeFrom", obj.getDeletionTimeFrom());
		} else {
			st.setObject("deletion_timeFrom", null);
		}
		if (obj.getDeletionTimeTo() != null) {
			st.setObject("deletion_timeTo", obj.getDeletionTimeTo());
		} else {
			st.setObject("deletion_timeTo", null);
		}

		return st.getPreparedStatement();
	}

	/*
	 * private String fillHtmlTemplate(String template) { String html = template
	 * .replace(":id", Integer.toString(_id)) .replace(":id_quotation",
	 * Integer.toString(_id_quotation)) .replace(":id_parent",
	 * Integer.toString(_id_parent)) .replace(":code", HtmlUtil.genHtml(_code))
	 * .replace(":name", HtmlUtil.genHtml(_name)) .replace(":description",
	 * HtmlUtil.genHtml(_description)) .replace(":remark",
	 * HtmlUtil.genHtml(_remark)) .replace(":is_group",
	 * HtmlUtil.genHtml(_isis_groupSet, _is_group)) .replace(":index",
	 * Integer.toString(_index)) .replace(":display_index",
	 * HtmlUtil.genHtml(_display_index)) .replace(":id_product",
	 * Integer.toString(_id_product)) .replace(":id_service",
	 * Integer.toString(_id_service)) .replace(":id_unit",
	 * Integer.toString(_id_unit)) .replace(":id_currency",
	 * Integer.toString(_id_currency)) .replace(":estimate_quantity",
	 * Integer.toString(_estimate_quantity)) .replace(":quotation_quantity",
	 * Integer.toString(_quotation_quantity)) .replace(":internal_quantity",
	 * Integer.toString(_internal_quantity)) .replace(":estimate_unit_cost",
	 * StringUtil.toString(_estimate_unit_cost))
	 * .replace(":quotation_unit_cost",
	 * StringUtil.toString(_quotation_unit_cost))
	 * .replace(":internal_unit_cost", StringUtil.toString(_internal_unit_cost))
	 * .replace(":estimate_total_amount",
	 * StringUtil.toString(_estimate_total_amount))
	 * .replace(":quotation_total_amount",
	 * StringUtil.toString(_quotation_total_amount))
	 * .replace(":internal_total_amount",
	 * StringUtil.toString(_internal_total_amount)) .replace(":in_estimate",
	 * HtmlUtil.genHtml(_isin_estimateSet, _in_estimate))
	 * .replace(":in_quotation", HtmlUtil.genHtml(_isin_quotationSet,
	 * _in_quotation)) .replace(":in_internal",
	 * HtmlUtil.genHtml(_isin_internalSet, _in_internal)) .replace(":id_type",
	 * Integer.toString(_id_type)) .replace(":status",
	 * Integer.toString(_status)) .replace(":notification",
	 * Integer.toString(_notification)) .replace(":created",
	 * StringUtil.toDateTimeString(_created)) .replace(":creator",
	 * Integer.toString(_creator)) .replace(":updated",
	 * StringUtil.toDateTimeString(_updated)) .replace(":updator",
	 * Integer.toString(_updator)) .replace(":deleted",
	 * HtmlUtil.genHtml(_isdeletedSet, _deleted)) .replace(":deletion_time",
	 * StringUtil.toDateTimeString(_deletion_time))
	 * 
	 * ; return html; }
	 */

	/*
	 * private String fillHtmlTemplate(String template) { String html = template
	 * .replace(":Id", Integer.toString(_Id)) .replace(":IdQuotation",
	 * Integer.toString(_IdQuotation)) .replace(":IdParent",
	 * Integer.toString(_IdParent)) .replace(":Code", HtmlUtil.genHtml(_Code))
	 * .replace(":Name", HtmlUtil.genHtml(_Name)) .replace(":Description",
	 * HtmlUtil.genHtml(_Description)) .replace(":Remark",
	 * HtmlUtil.genHtml(_Remark)) .replace(":IsGroup",
	 * HtmlUtil.genHtml(_isIsGroupSet, _IsGroup)) .replace(":Index",
	 * Integer.toString(_Index)) .replace(":DisplayIndex",
	 * HtmlUtil.genHtml(_DisplayIndex)) .replace(":IdProduct",
	 * Integer.toString(_IdProduct)) .replace(":IdService",
	 * Integer.toString(_IdService)) .replace(":IdUnit",
	 * Integer.toString(_IdUnit)) .replace(":IdCurrency",
	 * Integer.toString(_IdCurrency)) .replace(":EstimateQuantity",
	 * Integer.toString(_EstimateQuantity)) .replace(":QuotationQuantity",
	 * Integer.toString(_QuotationQuantity)) .replace(":InternalQuantity",
	 * Integer.toString(_InternalQuantity)) .replace(":EstimateUnitCost",
	 * StringUtil.toString(_EstimateUnitCost)) .replace(":QuotationUnitCost",
	 * StringUtil.toString(_QuotationUnitCost)) .replace(":InternalUnitCost",
	 * StringUtil.toString(_InternalUnitCost)) .replace(":EstimateTotalAmount",
	 * StringUtil.toString(_EstimateTotalAmount))
	 * .replace(":QuotationTotalAmount",
	 * StringUtil.toString(_QuotationTotalAmount))
	 * .replace(":InternalTotalAmount",
	 * StringUtil.toString(_InternalTotalAmount)) .replace(":InEstimate",
	 * HtmlUtil.genHtml(_isInEstimateSet, _InEstimate)) .replace(":InQuotation",
	 * HtmlUtil.genHtml(_isInQuotationSet, _InQuotation))
	 * .replace(":InInternal", HtmlUtil.genHtml(_isInInternalSet, _InInternal))
	 * .replace(":IdType", Integer.toString(_IdType)) .replace(":Status",
	 * Integer.toString(_Status)) .replace(":Notification",
	 * Integer.toString(_Notification)) .replace(":Created",
	 * StringUtil.toDateTimeString(_Created)) .replace(":Creator",
	 * Integer.toString(_Creator)) .replace(":Updated",
	 * StringUtil.toDateTimeString(_Updated)) .replace(":Updator",
	 * Integer.toString(_Updator)) .replace(":Deleted",
	 * HtmlUtil.genHtml(_isDeletedSet, _Deleted)) .replace(":DeletionTime",
	 * StringUtil.toDateTimeString(_DeletionTime))
	 * 
	 * ; return html; }
	 */

	// ADDED CODE

	// public String fillHtmlTemplate(String template) {
	// String html = template
	// .replace(":id", Integer.toString(_id))
	// .replace(":id_quotation", Integer.toString(_id_quotation))
	// .replace(":id_parent", Integer.toString(_id_parent))
	// .replace(":code", HtmlUtil.genHtml(_code))
	// .replace(":name", HtmlUtil.genHtml(_name))
	// .replace(":description", HtmlUtil.genHtml(_description))
	// .replace(":remark", HtmlUtil.genHtml(_remark))
	// .replace(":is_group",
	// HtmlUtil.genHtml(_isis_groupSet, _is_group))
	// .replace(":index", Integer.toString(_index))
	// .replace(":display_no", HtmlUtil.genHtml(_display_index))
	// .replace(":id_unit", Integer.toString(_id_unit))
	// // .replace(":quantity", Integer.toString(_quantity))
	// .replace(":id_currency", Integer.toString(_id_currency))
	// // .replace(":unit_cost", StringUtil.toString(_unit_cost))
	// // .replace(":total_amount", StringUtil.toString(_total_amount))
	// .replace(":id_type", Integer.toString(_id_type))
	// .replace(":status", Integer.toString(_status))
	// .replace(":notification", Integer.toString(_notification))
	// .replace(":created", StringUtil.toDateTimeString(_created))
	// .replace(":creator", Integer.toString(_creator))
	// .replace(":updated", StringUtil.toDateTimeString(_updated))
	// .replace(":updator", Integer.toString(_updator))
	// .replace(":deleted", HtmlUtil.genHtml(_isdeletedSet, _deleted))
	// .replace(":deletion_time",
	// StringUtil.toDateTimeString(_deletion_time));
	// return html;
	// }

	// ADDED CODE

	private QuotationItemModel _parent = null;
	private List<QuotationItemModel> _childNodes = new ArrayList<QuotationItemModel>();
	private int _level = 0;

	@Override
	public int compareTo(ITreeNode o) {
		QuotationItemModel obj = (QuotationItemModel) o;
		int res = StringUtil.compareStrings(_display_index,
				obj.getDisplayIndex());
		return res;
	}

	@Override
	public List<ITreeNode> getChildNodes() {
		List<ITreeNode> res = new ArrayList<ITreeNode>();
		for (QuotationItemModel obj : _childNodes) {
			res.add(obj);
		}
		return res;
	}

	@Override
	public void addChildNode(ITreeNode childNode) {
		_childNodes.add((QuotationItemModel) childNode);
	}

	@Override
	public int getLevel() {
		return _level;
	}

	@Override
	public void setLevel(int level) {
		_level = level;
	}

	@Override
	public ITreeNode getParent() {
		return _parent;
	}

	@Override
	public void setParent(ITreeNode parent) {
		_parent = (QuotationItemModel) parent;
	}

	private boolean _addedToTree = false;

	@Override
	public boolean getAddedToTree() {
		return _addedToTree;
	}

	@Override
	public void setAddedToTree(boolean added) {
		_addedToTree = added;
	}
}